<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Catalog</title>
</head>
<body>
<body background="../img/bg.jpg"> 
	<font face="Berlin Sans FB Demi" color="#357EC7" size="3">
<center>
<br><br><br><br>
<h1>Adauga note si/sau absente</h1>
	<?
error_reporting (E_ALL ^ E_NOTICE);
include('auth.php');
include('../config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {die('Failed to connect to server: ' . mysql_error());}
           
$db = mysql_select_db(DB_DATABASE);
if(!$db) {die("Unable to select database");}
?>
<b>

<form action='clasa.php' method="post">
<table border="1">
<tr><td>Selectare elev: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="elev">
<?
$sql=mysql_query("select nume from elev where clasa='".$_POST['clasa']."'");
while ($result=mysql_fetch_array($sql)) {
echo "<option>".$result['nume']."</option>";
}
?>
</select></td></tr>
<tr><td>Selectare materie: <select name="materie">
<?
$sql=mysql_fetch_array(mysql_query("select id from profesori where nume='".$_POST['prof']."'"));
$id=$sql['id'];
$sql3=mysql_query("SELECT *,materie.nume, profesori.nume as prof
FROM clase, materie, profesori
WHERE clase.materie_id = materie.id
AND clase.profesor_id ='".$id."' and clase.nume='".$_POST['clasa']."' group by materie.nume");
while ($result1=mysql_fetch_array($sql3)){
echo "<option>".$result1['nume']."</option>";
}
?>
</select></td></tr>
<tr><td>Nota: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="nota"></tr></td>
<tr><td>Absenta: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="abs"></tr></td>
<tr><td><center><input type="submit" value="OK"></center></tr></td>
</form>
<?
function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}
$elev=clean($_POST['elev']);
$mat=clean($_POST['materie']);
$nota=clean($_POST['nota']);
$abs=clean($_POST['abs']);
$mat2=mysql_fetch_array(mysql_query("select id from materie where nume='".$mat."'"));
$idmat=$mat2[0];
$elev2=mysql_fetch_array(mysql_query("select id from elev where nume='".$elev."'"));
$idelev=$elev2[0];
$s=explode('/',$nota);
$abs1=explode('-',$abs);
if ($nota!='') {
$sql=mysql_query("insert into note(elev_id,materie_id,nota) values ('".$idelev."','".$idmat."','".$nota."')");
if ($nota<=5) {
$email=mysql_fetch_array(mysql_query("select * from elev where nume='".$elev."'"));
mail($email['email_parinte'],'Nota mica',"Copilul dvs,".$elev.", a obtinut nota ".$s[0]." la materia ".$mat." in data de ".$s[1]."",'From: fast_michael98@yahoo.com');
}
header('location: admin.php');
}
if ($abs!='') {
$sql2=mysql_query("insert into elev_has_materie(elev_id,materie_id,abs) values ('".$idelev."','".$idmat."','".$abs."')");
$email=mysql_fetch_array(mysql_query("select * from elev where nume='".$elev."'"));
if (strtolower($abs1[1])=='nemotivata') {
mail($email['email_parinte'],'Absenta nemotivata',"Copilul dvs,".$elev.", are o absenta ".strtolower($abs1[1])." la materia ".$mat." in data de ".$abs1[0]."",'From: fast_michael98@yahoo.com');
}
header('location: admin.php');
}

?>
</font>
</center>
</body>
</html>